package com.ice.crm.activity.service.impl;

import com.ice.crm.activity.mapper.ActivityMapper;
import com.ice.crm.activity.model.Activity;
import com.ice.crm.activity.service.ActivityService;
import com.ice.crm.commons.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class ActivityServiceImpl implements ActivityService {

    @Resource
    private ActivityMapper activityMapper;

    @Override
    public Page selectActivityLimit(Integer userId, Integer pageNum, Integer pageSize, String name, String ownerName, String startDate, String endDate) {
        // 总记录数是通过数据库查询得到的
        Integer total = activityMapper.selectCountByUserId(userId, name, ownerName, startDate, endDate);
        Page page = new Page(pageNum, pageSize, total);
        // 查询分页的数据
        List<Map> list = activityMapper.selectActivityByUserId(userId, page.getSkipNum(), page.getPageSize(), name, ownerName, startDate, endDate);
        page.setDataList(list);
        return page;
    }

    @Override
    public void activityDelete(Integer activityIds[]) {
        for (Integer i : activityIds) {
            activityMapper.updateByActivityId(i, 0);
        }
    }

    @Override
    public void activityAdd(Activity activity) {
        activityMapper.insert(activity);
    }
}
